package com.ruoyi.dispatch.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.dispatch.vo.ProductionMonthPlanVO;
import com.ruoyi.framework.utils.BeanCopyUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dispatch.domain.ProductionMonthPlan;
import com.ruoyi.dispatch.service.IProductionMonthPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回采月计划Controller
 * 
 * @author wuxiaofang
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/dispatch/productionMonthPlan")
@Anonymous
public class ProductionMonthPlanController extends BaseController
{
    @Autowired
    private IProductionMonthPlanService productionMonthPlanService;

    /**
     * 查询回采月计划列表
     */
    @PreAuthorize("@ss.hasPermi('dispatch:productionMonthPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionMonthPlan productionMonthPlan)
    {
        startPage();
        List<ProductionMonthPlan> list = productionMonthPlanService.selectProductionMonthPlanList(productionMonthPlan);
        return getDataTable(list);
    }

    /**
     * 导出回采月计划列表
     */
    @PreAuthorize("@ss.hasPermi('dispatch:productionMonthPlan:export')")
    @Log(title = "回采月计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionMonthPlan productionMonthPlan)
    {
        List<ProductionMonthPlan> list = productionMonthPlanService.selectProductionMonthPlanList(productionMonthPlan);
        ExcelUtil<ProductionMonthPlan> util = new ExcelUtil<ProductionMonthPlan>(ProductionMonthPlan.class);
        util.exportExcel(response, list, "回采月计划数据");
    }

    /**
     * 获取回采月计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('dispatch:productionMonthPlan:query')")
    @GetMapping(value = "/{proMonthPlanId}")
    public AjaxResult getInfo(@PathVariable("proMonthPlanId") Long proMonthPlanId)
    {
        return success(productionMonthPlanService.selectProductionMonthPlanByProMonthPlanId(proMonthPlanId));
    }

    /**
     * 新增回采月计划
     */
    @PreAuthorize("@ss.hasPermi('dispatch:productionMonthPlan:add')")
    @Log(title = "回采月计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionMonthPlan productionMonthPlan)
    {
        return toAjax(productionMonthPlanService.insertProductionMonthPlan(productionMonthPlan));
    }

    /**
     * 修改回采月计划
     */
    @PreAuthorize("@ss.hasPermi('dispatch:productionMonthPlan:edit')")
    @Log(title = "回采月计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionMonthPlan productionMonthPlan)
    {
        return toAjax(productionMonthPlanService.updateProductionMonthPlan(productionMonthPlan));
    }

    /**
     * 删除回采月计划
     */
    @PreAuthorize("@ss.hasPermi('dispatch:productionMonthPlan:remove')")
    @Log(title = "回采月计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{proMonthPlanIds}")
    public AjaxResult remove(@PathVariable Long[] proMonthPlanIds)
    {
        return toAjax(productionMonthPlanService.deleteProductionMonthPlanByProMonthPlanIds(proMonthPlanIds));
    }

    /**
     * 生成指定月份回采月计划数据
     * @param month
     * @return
     */
    @RequestMapping("/genProMonthPlan")
    public AjaxResult genProMonthPlan(String month){
        List<ProductionMonthPlan> monthPlanList = productionMonthPlanService.copyLastMonthPlan(month);
        List<ProductionMonthPlanVO> vo = BeanCopyUtils.copyListProperties(monthPlanList, ProductionMonthPlanVO.class);
        return toAjax(vo.size(),vo);
    }
}
